﻿#!/usr/bin/env python3

import socket

def main():
    '''echo server -  copy from python help doc'''
    print(main.__doc__)
    print("="*30)

    HOST = ''                 # Symbolic name meaning all available interfaces
    PORT = 50007              # Arbitrary non-privileged port
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.bind((HOST, PORT))
        s.listen(1)
        conn, addr = s.accept()
        with conn:
            print('Connected by', addr)
            while True:
                data = conn.recv(1024)
                print(len(data))
                if not data: 
                    print("break")
                    break
                conn.sendall(data)
                print("send back")


if __name__=='__main__':
    main()
